前面講了新增修改刪除 category
今天來講 點 類別 進去 可以看到 細節
store/urls.py
...
path('categoryRead/<int:id>/', views.categoryRead, name='categoryRead'),
...
store/views.py
...
def categoryRead(request, id):
category = get_object_or_404(Category, id=id)
return render(request, 'store/categoryRead.html', {'category': category})
...
store/templates/store/category.html
...
<td><a href="{% url 'store:categoryRead' category.id %}">{{ category.name }}</a></td>
...
新增
store/templates/store/categoryRead.html
{% extends 'main/base.html' %}
{% block content %}
{% if category %}
<div>
<div>
類別: {{ category.name }}
</div>
</div>
{% endif %}
{% endblock %}
這樣就完成了